package main

import (
	"fmt"
	"net"
	"time"
)

func main6() {
	localAddress := &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 3000}
	conn, err := net.ListenUDP("udp", localAddress)
	if err != nil {
		fmt.Printf("监听错误: %s", err)
		return
	}
	remoteAddress := &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 2000}
	_, err = conn.WriteToUDP([]byte("hello"), remoteAddress)
	if err != nil {
		fmt.Printf("消息发送错误：%v", err)
		return
	}

	time.Sleep(1000)

	data := make([]byte, 1024)
	n, _ := conn.Read(data)
	fmt.Printf("收到消息：%s\n", data[:n])
}
